Graceful error handling for offline scenarios in 'aspire new' and 'aspire add' commands#9458
Merged
Graceful error handling for offline scenarios in 'aspire new' and 'aspire add' commands#9458
Conversation
Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Graceful error handling for offline scenarios in 'aspire new' and 'aspire add' commands
Graceful error handling for offline scenarios in 'aspire new' and 'aspire add' commands
May 22, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
Adds graceful handling of offline scenarios for aspire new and aspire add by throwing and catching a dedicated exception when no templates or packages are available.
- Introduces
EmptyChoicesExceptionand guards prompts against empty collections - Updates
InteractionServiceto throw on empty choices and enhancesNewCommand/AddCommandwith checks and catch blocks - Adds unit tests covering empty-choice scenarios in the interaction layer and the two commands
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Aspire.Cli.Tests/TestServices/TestInteractionService.cs | test stub that throws EmptyChoicesException for empty prompts |
| tests/Aspire.Cli.Tests/Interaction/InteractionServiceTests.cs | new test for PromptForSelectionAsync with no choices |
| tests/Aspire.Cli.Tests/Commands/NewCommandTests.cs | new test for empty-template error handling in NewCommand |
| tests/Aspire.Cli.Tests/Commands/AddCommandTests.cs | new test for empty-package error handling in AddCommand |
| src/Aspire.Cli/Interaction/InteractionService.cs | added empty-check and throw in PromptForSelectionAsync |
| src/Aspire.Cli/Interaction/EmptyChoicesException.cs | introduced EmptyChoicesException class |
| src/Aspire.Cli/Commands/NewCommand.cs | added empty-list guard and catch in NewCommand |
| src/Aspire.Cli/Commands/AddCommand.cs | added empty-list guard and catch in AddCommand |
Member
|
I think this is good to go. |
davidfowl
approved these changes
May 22, 2025
davidfowl
approved these changes
May 22, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When running the
aspire neworaspire addcommands without an internet connection, the CLI attempts to prompt the user to select from a list of available template versions or packages. Since no templates/packages are available offline, this results in an unhandled exception (System.InvalidOperationException: Cannot show an empty selection prompt).Changes
This PR adds proper error handling for offline scenarios by:
EmptyChoicesExceptionclass to handle cases with no available choicesInteractionService.PromptForSelectionAsyncmethod to check if the choices collection is empty before attempting to prompt the userUser Experience
When offline or when no templates/packages are found, the user will now receive clear error messages like:
Testing
Added tests for:
InteractionServiceNewCommandandAddCommandFixes #9457.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
dnceng.pkgs.visualstudio.com/home/REDACTED/work/aspire/aspire/.dotnet/dotnet build src/Aspire.Cli/Aspire.Cli.csproj(dns block)/home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj --filter FullyQualifiedName~InteractionServiceTests|FullyQualifiedName~AddCommand_EmptyPackageList|FullyQualifiedName~NewCommand_EmptyPackageList(dns block)pkgs.dev.azure.com/home/REDACTED/work/aspire/aspire/.dotnet/dotnet build src/Aspire.Cli/Aspire.Cli.csproj(dns block)/home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj --filter FullyQualifiedName~InteractionServiceTests|FullyQualifiedName~AddCommand_EmptyPackageList|FullyQualifiedName~NewCommand_EmptyPackageList(dns block)/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.